Repository navigation
Skip Cloudflare runtime startup during type generation - #16961
Conversation
🦋 Changeset detectedLatest commit: 95b9339 The changes in this PR will be included in the next version bump. This PR includes changesets to release 37 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
| // Avoid starting the Cloudflare dev runtime during type generation. See #16332. | ||
| if (isTypeGenOnly) { | ||
| for (const plugin of cloudflareVitePlugins) { | ||
| plugin.configureServer = undefined; |
There was a problem hiding this comment.
does this currently start the dev server during the build? I assume it probably does not.. but not obvious from the logic.
I'm betting that the server starts in sync by not in the build. in which case I would suggest getting rid of the variable and just inlining the conditions with a comment, as the variable could make someone thing something is wrong that the configureServer function is removed from the build.
There was a problem hiding this comment.
build does start the Cloudflare runtime during its internal type-gen pass: it calls syncInternal({ command: 'build' }) (core/build/index.ts#L174), which spins up a temporary Vite server — and creating that server fires every plugin’s configureServer, including @cloudflare/vite-plugin’s. The only way to skip it is the programmatic sync: false path, which isn’t what astro build does.
So the cleanest fix is to strip configureServer from the plugin during this phase. The other time saver is skipping dep pre-bundling in the same phase.
We could inline the condition in both places or maybe rename the variable to something like isTypeGenPhase or skipCloudflareRuntime. What do you think?
There was a problem hiding this comment.
Variable name doesn't matter so much as understanding what you just said, so if you could just add a comment that explains why its needed for both that will be enough.
* fix(cloudflare): skip runtime startup during type generation * docs(cloudflare): explain why type-gen runtime skip covers build and sync
The actions-build fixture test could not fail when the withastro#16961 guard was reverted: it pinned prerenderEnvironment 'node' (skipping the default workerd prerender path), its second build was a pure optimizer cache hit rather than a stale-cache scenario, and its assertions never touched Actions output. Replace it with a unit test that invokes the adapter's astro:config:setup hook directly and asserts both observable effects of the isTypeGenPhase guard: configureServer is stripped from the Cloudflare Vite plugins and dependency discovery is disabled for every environment during build/sync, while dev keeps both. Verified the new test fails when the guard is neutered to sync-only or removed. Restore buildWithRetry: the stale-prebundle race it guards (withastro#14821) was never root-caused or fixed, and the suite runs all 49 files serially in one process with no CI-level retry to absorb a flake. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The actions-build fixture test could not fail when the withastro#16961 guard was reverted: it pinned prerenderEnvironment 'node' (skipping the default workerd prerender path), its second build was a pure optimizer cache hit rather than a stale-cache scenario, and its assertions never touched Actions output. Replace it with a unit test that invokes the adapter's astro:config:setup hook directly and asserts both observable effects of the isTypeGenPhase guard: configureServer is stripped from the Cloudflare Vite plugins and dependency discovery is disabled for every environment during build/sync, while dev keeps both. Verified the new test fails when the guard is neutered to sync-only or removed. Restore buildWithRetry: the stale-prebundle race it guards (withastro#14821) was never root-caused or fixed, and the suite runs all 49 files serially in one process with no CI-level retry to absorb a flake.
Changes
astro syncwas much slower with@astrojs/cloudflarebecause type generation started the Cloudflare dev runtime even though no requests are served. During the invocation of the temporary type generation dev server, the adapter now:configureServerfrom@cloudflare/vite-pluginplugins so the Cloudflare dev runtime never starts.optimizeDeps: { noDiscovery: true, include: [] }on every environment so no dependencies are pre-bundled.devandpreviewcontinue to start the Cloudflare runtime as expected.Testing
astro synctype generation with the MRE:astro sync@astrojs/node@astrojs/vercel@astrojs/netlify@astrojs/cloudflare(before)@astrojs/cloudflare(after)Docs
Closes #16332